package com.example.administrator.orchardeveryday;

import android.app.Application;
import android.widget.Toast;

import com.example.administrator.orchardeveryday.bean.dbbean.User;
import com.example.administrator.orchardeveryday.netstate.NetChangeObserver;
import com.example.administrator.orchardeveryday.netstate.NetWorkUtil;
import com.example.administrator.orchardeveryday.netstate.NetworkStateReceiver;
import com.example.administrator.orchardeveryday.utils.ImageLoaderUtils;

/**
 * Created by Administrator on 15-10-19.
 */
public class BaseApp extends Application{
    private static BaseApp app;
    public static User user=new User();
    public static BaseApp getInstance() {
        return app;
    }
    private NetChangeObserver observer = new NetChangeObserver() {
        @Override
        public void onConnect(NetWorkUtil.NetType type) {
            super.onConnect(type);
            switch (type) {
                case WIFI:
                    showToast("亲!WIFI已连接");
                    break;
                case GNET_3:
                    showToast("移动3G网络已连接!!!");
                    break;
                default:
                    showToast("亲!网络已连接");
                    break;
            }
        }
        @Override
        public void onDisConnect() {
            super.onDisConnect();
            showToast("网络未连接,请打开网络!!!");
        }
    };

    @Override
    public void onCreate() {
        super.onCreate();
        app=this;
        initNetState();
        ImageLoaderUtils.configGlobalImageLoader(this);

    }
    private void initNetState() {
        NetworkStateReceiver.registerNetworkStateReceiver(this);
        NetworkStateReceiver.registerObserver(observer);
    }
    public void unegisterNetworkStateReceiver() {
        NetworkStateReceiver.removeRegisterObserver(observer);
        NetworkStateReceiver.unRegisterNetworkStateReceiver(this);
    }
    public void showToast(String msg)
        {
            Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
        }
}
